perf(browser): pre-bundle the vitest runtime in optimizeDeps#10713
Open
sheremet-va wants to merge 1 commit into
Open
perf(browser): pre-bundle the vitest runtime in optimizeDeps#10713sheremet-va wants to merge 1 commit into
sheremet-va wants to merge 1 commit into
Conversation
757bed9 to
8e26a98
Compare
1c277fb to
70c9635
Compare
hi-ogawa
reviewed
Jul 7, 2026
Member
Author
|
There are already 4 PRs stacked on top of each other 😩 It’s gonna be a merge headache. I’ll ask claude to split it 😔 |
1 task
70c9635 to
497a8bc
Compare
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The browser now fetches a few optimized chunks instead of ~20 separately-served dist chunks. vitest, vitest/internal/browser and @vitest/browser/client are optimized in a single pass so esbuild dedupes their shared stateful chunks, preserving module identity between the test files' import of 'vitest' and the tester. Frames from the optimizer cache (.vite/vitest) are ignored in stack traces like the un-bundled dist ones.
497a8bc to
a163920
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-bundles the vitest runtime for browser mode so the browser fetches a few optimized chunks instead of ~20 separately-served dist chunks (faster startup, fewer module requests).
vitest,vitest/internal/browserand@vitest/browser/clientare moved fromoptimizeDeps.excludetoinclude. They are optimized together in a single pass, so esbuild dedupes their shared stateful chunks (the test collector, the runner, the RPC client) to a single instance — preserving module identity between the test files'import 'vitest'and the tester. Their transitive deps (@vitest/utils,@vitest/spy,pathe,tinyrainbow, …) are inlined into these bundles. The virtual per-server modules (@vitest/browser/context, …),vite/module-runnerandmswmust stay excluded (see the comment inindex.ts).Shared-server resolver fix. The
vitest:resolve-coreplugin (vitestResolver.ts) short-circuits barevitestimports straight to the running copy's dist file. It now lives on the single Vite server shared by every environment, so it also governs the browserclientenvironment where the runtime is pre-bundled — without care the tester would use the optimized bundle while test files receive the raw dist graph, producing two@vitest/runnerinstances and failing everytest()with "Vitest failed to find the current suite". When the environment includesvitestinoptimizeDeps, the plugin now routes the import through the optimizer (this.resolve) so both share one instance; every other environment keeps the pinned dist resolution.Stack frames pointing into the optimizer cache (
.vite/vitest) are ignored in stack traces like the un-bundled/vitest/dist/ones. The console-logging spec now runs with an explicitdefaultreporter and asserts on Vitest's own console forwarding: once the runtime is pre-bundled the tester loads a stubbed@vite/client, so Vite's client console relay no longer runs.